#include<bits/stdc++.h>
using namespace std;

class DetectSquares {
public:

    inline int calc(int x, int y){return x * 1001 + y;}

    vector<unordered_set<int>> find_points_by_y;
    unordered_map<int, int>mp;// x * 1001 + y
    DetectSquares() {
        find_points_by_y = vector<unordered_set<int>>(1001);
        mp.clear();
    }
    
    void add(vector<int> point) {
        mp[calc(point[0], point[1])]++;
        find_points_by_y[point[1]].insert(point[0]);
    }
    
    int count(vector<int> point) {
        int res = 0;
        if(!find_points_by_y[point[1]].size())return 0;
        for(auto item : find_points_by_y[point[1]]){
            if(item != point[0]){
                int d = point[0] - item;
                int a = mp[calc(item, point[1])], 
                    b = mp[calc(point[0], point[1] - d)],
                    c = mp[calc(item, point[1] - d)];
                res += a * b * c;

                b = mp[calc(point[0], point[1] + d)],
                c = mp[calc(item, point[1] + d)];
                res += a * b * c;
            }
        }
        return res;
    }
};

/**
 * 2021.9.19
 * 周赛第三题
 */ 